package com.qinyh.view;

import android.app.ProgressDialog;
import android.content.Context;
import android.view.MotionEvent;

public  class MyProgressDialog extends ProgressDialog {
	public MyProgressDialog(Context context) {
		super(context);
	}

	private int x=-1;
	private MyProgresDialogCallBack callback;
	public void setX(int x){
		this.x=x;
	}
	private int scale;
	public int getScale(){
		return scale;
	}
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		int action = event.getAction();
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			this.incrementProgressBy(-this.getProgress());
			this.incrementProgressBy((int)(event.getX()*100/x));
			break;
		case MotionEvent.ACTION_MOVE:
			this.incrementProgressBy(-this.getProgress());
			this.incrementProgressBy((int)(event.getX()*100/x));
			break;
		case MotionEvent.ACTION_UP:
			this.incrementProgressBy(-this.getProgress());
			this.incrementProgressBy((int)(event.getX()*100/x));
			this.scale = (int)(event.getX()*100/x);
			if(this.callback!=null){
				callback.callback(scale);
			}
			this.dismiss();
			break;
		}
		return true;
	}
	public void setCallBack(MyProgresDialogCallBack callback){
		this.callback=callback;
	}
	public interface MyProgresDialogCallBack{
	public void	callback(int scale);
	}
}

